package com.example.demo.service.db2;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.example.demo.entity.User;
import com.example.demo.mapper.db2.UserMapper_db2;

@Component
public class Db2Service {
	
	@Autowired
	public UserMapper_db2 db2;

	/**
	 * 查询demo
	 * @return
	 */
	public User selectuser() {
		return db2.selectuser();
	}

	/**
	 * 添加demo
	 * @param user
	 * @return
	 */
	//默认事物可以不用写名称
	//直接使用的是@Transactional
	@Transactional("transAction_db2")
	public Map<String,Object> insert(User user) {
		 db2.insert(user);
		 if("zhu".equals(user.getName())) {
			throw new RuntimeException("回滚操作");
		 }
		 Map<String,Object> res = new HashMap<String,Object>();
		 res.put("status", 0);
		 res.put("message", "添加成功");
		 return res;
	}
}
